﻿@model IList<BB.Apostas.ViewModels.ApostaViewModel>
@if (Model.Count > 0)
{
    using (Html.BeginForm("Apostar", "Aposta"))
    {
    @Html.ValidationSummary()
    <table>
        <thead>
            <tr>
                <th>
                    Jogo
                </th>
                <th>
                    Data
                </th>
                <th>
                    Realizado
                </th>
                <th>
                    Resultado
                </th>
                <th>
                    Aposta
                </th>
                <th>
                    Pontos
                </th>
            </tr>
        </thead>
        <tbody>
            @{int count = 0;}
            @for (int i = 0; i < Model.Count(); i++)
            {          
                <tr>
                    <td>
                        @Html.DisplayFor(modelitem => modelitem[i].HomeTeam) -
                        @Html.DisplayFor(modelitem => modelitem[i].AwayTeam)
                    </td>
                    <td>
                        @Html.DisplayFor(modelitem => modelitem[i].Date)
                    </td>
                    <td>
                        @Html.DisplayFor(modelitem => modelitem[i].Fulfilled)
                    </td>
                    <td>
                        @Html.DisplayFor(modelitem => modelitem[i].HomeScore) - @Html.DisplayFor(modelitem => modelitem[i].AwayScore)
                    </td>
                    <td>
                        @if (Model[i].Fulfilled)
                        {
                            count += 1;
                            @Html.TextBoxFor(modelitem => modelitem[i].HomeBet, new { @style = "width:20px", disabled = true })
                            <span>-</span>
                            @Html.TextBoxFor(modelitem => modelitem[i].AwayBet, new { @style = "width:20px", disabled = true })
                        }
                        else
                        {
                            @Html.TextBoxFor(modelitem => modelitem[i].HomeBet, new { @style = "width:20px" })                            
                            <span>-</span>
                            @Html.TextBoxFor(modelitem => modelitem[i].AwayBet, new { @style = "width:20px" })
                        }
                        @Html.HiddenFor(modelitem => modelitem[i].ApostaId)
                        @Html.HiddenFor(modelitem => modelitem[i].JogoId)
                        @Html.HiddenFor(modelitem => modelitem[i].Date)
                    </td>
                    <td>
                        @Html.DisplayFor(modelitem => modelitem[i].Score)
                    </td>
                </tr>
            }
        </tbody>
        <tfoot>
            <tr>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                    <strong>Total:</strong>
                </td>
                <td>
                    <strong>@ViewBag.TotalScore</strong>
                </td>
            </tr>
        </tfoot>
    </table>
            if (count != System.Web.Configuration.WebConfigurationManager.AppSettings["NumJogos"].AsInt())
            {
    <div class="form_settings" style="float: right">
        <p>
            <span>&nbsp;</span>
            <input type="submit" value="Apostar" class="submit" />
        </p>
    </div>
            }
    }
}
else
{
    <h2>
        Apostas ainda nao disponiveis.
    </h2>
}
<div>
    @Html.ActionLink("Voltar", "Index")
</div>
